Skip to content

Conversation

@trentm
Copy link
Contributor

@trentm trentm commented Feb 27, 2025

  • chore(*)!: Update to 2.x and 0.200.x @opentelemetry/* packages from opentelemetry-js.git
    per https://github.com/open-telemetry/opentelemetry-js/blob/main/doc/upgrade-to-2.x.md
    • The minimum supported Node.js has been raised to ^18.19.0 || >=20.6.0. This means that support for Node.js 14 and 16 has been dropped.
    • The minimum supported TypeScript version has been raised to 5.0.4.
    • The compilation target for transpiled TypeScript has been raised to ES2022 (from ES2017).
  • chore(resource-detector-container)!: ContainerDetector class is no longer exported
  • chore(resource-detector-aws)!: merge Sync and async resources
    • removed awsBeanstalkDetectorSync -> use awsBeanstalkDetector
    • removed awsEc2DetectorSync -> use awsEc2Detector
    • removed awsEcsDetectorSync -> use awsEcsDetector
    • removed awsEksDetectorSync -> use awsEksDetector
    • removed awsLambdaDetectorSync -> use awsLambdaDetector
    • no longer exporting the detector classes: AwsBeanstalkDetector, AwsEcsDetector, AwsEksDetector, AwsLambdaDetector,
  • feat(resource-detector-instana): suppress tracing of the detectors internal HTTP requests

note to revewiers

This is ready for review. The remaining failing test will be fixed when there is a new release of 2.x/0.200.x from the core repo with open-telemetry/opentelemetry-js#5524 (see the checklist below).

checklist

- instr-bunyan and examples/bunyan
@codecov
Copy link

codecov bot commented Feb 27, 2025

Codecov Report

Attention: Patch coverage is 95.04717% with 21 lines in your changes missing coverage. Please review.

Project coverage is 91.73%. Comparing base (8e08755) to head (2bf52ff).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
...ce-detector-azure/src/detectors/AzureVmDetector.ts 77.14% 8 Missing ⚠️
...ource-detector-aws/src/detectors/AwsEksDetector.ts 91.66% 7 Missing ⚠️
...ource-detector-aws/src/detectors/AwsEcsDetector.ts 97.29% 3 Missing ⚠️
...detector-aws/src/detectors/AwsBeanstalkDetector.ts 96.77% 1 Missing ⚠️
...ource-detector-aws/src/detectors/AwsEc2Detector.ts 98.24% 1 Missing ⚠️
...resource-detector-gcp/src/detectors/GcpDetector.ts 96.77% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2738      +/-   ##
==========================================
- Coverage   91.86%   91.73%   -0.14%     
==========================================
  Files         171      166       -5     
  Lines        8172     8103      -69     
  Branches     1660     1546     -114     
==========================================
- Hits         7507     7433      -74     
- Misses        665      670       +5     
Files with missing lines Coverage Δ
...aba-cloud/src/detectors/AlibabaCloudEcsDetector.ts 98.14% <100.00%> (+0.18%) ⬆️
...ce-detector-aws/src/detectors/AwsLambdaDetector.ts 100.00% <100.00%> (ø)
...metry-resource-detector-aws/src/detectors/index.ts 100.00% <100.00%> (ø)
...tor-azure/src/detectors/AzureAppServiceDetector.ts 100.00% <100.00%> (ø)
...ctor-azure/src/detectors/AzureFunctionsDetector.ts 100.00% <100.00%> (ø)
...ector-container/src/detectors/ContainerDetector.ts 98.24% <100.00%> (+2.93%) ⬆️
...resource-detector-container/src/detectors/index.ts 100.00% <100.00%> (ø)
...metry-resource-detector-gcp/src/detectors/index.ts 100.00% <100.00%> (ø)
...ce-detector-github/src/detectors/GitHubDetector.ts 100.00% <100.00%> (ø)
...ctor-instana/src/detectors/InstanaAgentDetector.ts 96.92% <100.00%> (+0.25%) ⬆️
... and 15 more

... and 16 files with indirect coverage changes

🚀 New features to boost your workflow:
  • Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewer note: The updates to this file are just from the linter doing style changes. Normally .js files in the repo are not processed by npm run lint.

@JamieDanielson
Copy link
Member

Thanks for working on this! As discussed offline, let's update this or do a follow-up PR with some basic upgrade/migration notes for the resource detector change.

@trentm
Copy link
Contributor Author

trentm commented Mar 12, 2025

let's update this or do a follow-up PR with some basic upgrade/migration notes for the resource detector change.

Added here: open-telemetry/opentelemetry-js#5535

This shows there are some more test failures in instr-document-load to
deal with.
…ing.secureConnectionStart changed in sdk-trace-web
Copy link
Member

@pichlermarc pichlermarc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for working on this. 🙌

I pinged two component owners for their input on not exporting the detector classes anymore. In general I agree with that change and it also aligns them with the other detector packages. I think there's no benefit to having the classes exported. For the AWS detectors, which are stable, this is likely a good time to do this as dropping support for old Node.js versions means this will bump it to 2.0 anyway.

AwsBeanstalkDetectorSync,
awsBeanstalkDetectorSync,
} from './AwsBeanstalkDetectorSync';
export { awsBeanstalkDetector } from './AwsBeanstalkDetector';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While I agree with dropping class exports where they're not needed, I'm wondering: was this dropped intentionally?

cc @jj22ee: what's your preference - should the class export be kept? An end-user will likely just use the constant.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was intentional, yes, for the reasons you gave above:

  • The detector instance, e.g. awsBeanstalkDetector, is the thing users will want to use.
  • There is some precedent from the core repo's detector classes also having been dropped in the 2.0.0 release or earlier.
  • I don't know of a use case for exporting the class.
  • We have a breaking change version bump already for dropping Node 14 and 16 support, so it was an opportunity for this breaking change.

However, I don't feel strongly, so I'm okay to re-add exporting these if others feel we should.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for clarifying :)
I agree that we should drop class exports. It's also easy to add back later in a feature release if needed 👍

* limitations under the License.
*/
export * from './ContainerDetector';
export { containerDetector } from './ContainerDetector';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here, the class used to be exported, but the end-user never really needs to be a class. I'm fine with this change.

cc @abhee11 (component owner)

@david-luna david-luna self-requested a review March 17, 2025 12:13
} = await this._fetchIdentity();
const hostname = await this._fetchHost();
_getAttributes(): DetectedResourceAttributes {
const dataP = Promise.all([this._fetchIdentity(), this._fetchHost()]);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

running some tests in Elastic's distribution I got an error of an unhandled promise rejection

node ./test/agent-metadata.test.js
TAP version 13
# agent metadata
# agent metadata default case
not ok 1 exited successfully: err=Error: Command failed: /Users/david/.nvm/versions/node/v18.19.0/bin/node ./fixtures/use-http-get.js node:internal/process/promises:288 triggerUncaughtException(err, true /* fromPromise */); ^ Error: ECS metadata api request timed out. at Timeout._onTimeout (/Users/david/Documents/repos/otel/opentelemetry-js-contrib/detectors/node/opentelemetry-resource-detector-alibaba-cloud/build/src/detectors/AlibabaCloudEcsDetector.js:91:29) at listOnTimeout (node:internal/timers:569:17) at process.processTimers (node:internal/timers:512:7) Node.js v18.19.0 
  ---
    operator: error
    at: done (/Users/david/Documents/repos/el/elastic-otel-node/packages/opentelemetry-node/test/testutils.js:648:35)
    stack: |-
      Error: Command failed: /Users/david/.nvm/versions/node/v18.19.0/bin/node ./fixtures/use-http-get.js
      node:internal/process/promises:288
                  triggerUncaughtException(err, true /* fromPromise */);
                  ^
      
      Error: ECS metadata api request timed out.
          at Timeout._onTimeout (/Users/david/Documents/repos/otel/opentelemetry-js-contrib/detectors/node/opentelemetry-resource-detector-alibaba-cloud/build/src/detectors/AlibabaCloudEcsDetector.js:91:29)
          at listOnTimeout (node:internal/timers:569:17)
          at process.processTimers (node:internal/timers:512:7)
      
      Node.js v18.19.0
      
          at ChildProcess.exithandler (node:child_process:422:12)
          at ChildProcess.emit (node:events:517:28)
          at maybeClose (node:internal/child_process:1098:16)
          at ChildProcess._handle.onexit (node:internal/child_process:303:5)
  ...
# stdout:
# |{"name":"elastic-otel-node","level":30,"preamble":true,"distroVersion":"0.7.0","env":{"os":"darwin 24.3.0","arch":"arm64","runtime":"Node.js v18.19.0"},"msg":"start Elastic Distribution of OpenTelemetry Node.js","time":"2025-03-17T12:12:47.063Z"}
# |{"name":"elastic-otel-node","level":50,"msg":"Accessing resource attributes before async attributes settled","time":"2025-03-17T12:12:47.074Z"}
# |{"name":"elastic-otel-node","level":50,"msg":"Accessing resource attributes before async attributes settled","time":"2025-03-17T12:12:47.074Z"}
# |{"name":"elastic-otel-node","level":50,"msg":"Accessing resource attributes before async attributes settled","time":"2025-03-17T12:12:47.074Z"}
# |{"name":"elastic-otel-node","level":50,"msg":"Accessing resource attributes before async attributes settled","time":"2025-03-17T12:12:47.074Z"}
# |{"name":"elastic-otel-node","level":50,"msg":"Accessing resource attributes before async attributes settled","time":"2025-03-17T12:12:47.074Z"}
# |client response: 200 {
# |  date: 'Mon, 17 Mar 2025 12:12:47 GMT',
# |  expires: '-1',
# |  'cache-control': 'private, max-age=0',
# |  'content-type': 'text/html; charset=ISO-8859-1',
# |  'content-security-policy-report-only': "object-src 'none';base-uri 'self';script-src 'nonce-8TGjP3Y6JPSYBgb6x6Gcsg' 'strict-dynamic' 'report-sample' 'unsafe-eval' 'unsafe-inline' https: http:;report-uri https://csp.withgoogle.com/csp/gws/other-hp",
# |  server: 'gws',
# |  'x-xss-protection': '0',
# |  'x-frame-options': 'SAMEORIGIN',
# |  'set-cookie': [Array],
# |  'accept-ranges': 'none',
# |  vary: 'Accept-Encoding',
# |  connection: 'close',
# |  'transfer-encoding': 'chunked'
# |}
# |client response: end
# stderr:
# |node:internal/process/promises:288
# |            triggerUncaughtException(err, true /* fromPromise */);
# |            ^
# |
# |Error: ECS metadata api request timed out.
# |    at Timeout._onTimeout (/Users/david/Documents/repos/otel/opentelemetry-js-contrib/detectors/node/opentelemetry-resource-detector-alibaba-cloud/build/src/detectors/AlibabaCloudEcsDetector.js:91:29)
# |    at listOnTimeout (node:internal/timers:569:17)
# |    at process.processTimers (node:internal/timers:512:7)
# |
# |Node.js v18.19.0
# skip checkTelemetry because process errored out

1..1
# tests 1
# pass  0
# fail  1

In this detector and other that are doing async operations we have promises that need to be handled if they reject. I think is because now the detectResources method from @opentelemetry/resources does defer the handling of the rejected ones. Checking ResourceImpl constructor we see values are kept but not handled until waitForAsyncAttributes is called (I think in exporters).

We could solve it by being more eager on handling the async attributes in ResourceImpl or by handling all possible rejections in each detector. Doing the later means we should add a second callback function for each promised value in the attribs object. Something like

    const resolveUndef = () => undefined;
    return {
      [SEMRESATTRS_CLOUD_PROVIDER]: dataP.then(
        () => CLOUDPROVIDERVALUES_ALIBABA_CLOUD,
        resolveUndef
      ),
      [SEMRESATTRS_CLOUD_PLATFORM]: dataP.then(
        () => CLOUDPLATFORMVALUES_ALIBABA_CLOUD_ECS,
        resolveUndef
      ),

      // Data from _fetchIdentity()
      [SEMRESATTRS_CLOUD_ACCOUNT_ID]: dataP.then(
        data => data[0]['owner-account-id'],
        resolveUndef
      ),
      [SEMRESATTRS_CLOUD_REGION]: dataP.then(data => data[0]['region-id']),
      [SEMRESATTRS_CLOUD_AVAILABILITY_ZONE]: dataP.then(
        data => data[0]['zone-id']
      ),
      [SEMRESATTRS_HOST_ID]: dataP.then(
        data => data[0]['instance-id'],
        resolveUndef
      ),
      [SEMRESATTRS_HOST_TYPE]: dataP.then(
         data => data[0]['instance-type'],
        resolveUndef
      ),

      // Data from _fetchHost()
      [SEMRESATTRS_HOST_NAME]: dataP.then(
         data => data[1],
        resolveUndef
      ),
    };

Copy link
Contributor Author

@trentm trentm Mar 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@david-luna Thanks! I'll have to update most of the res detectors in this PR for this.

Some notes:

  • I think there is effectively a regression in @opentelemetry/[email protected] here. It doesn't adequately guard against a rejection in async resource attribute values anymore. I'll raise an issue (and perhaps PR) for this.
  • In the meantime, for a Resource Detector to use @opentelemetry/[email protected], the burden is now on the Resource Detector author to never have its async attribute promises reject.
  • I'm really curious why tests didn't catch this: some or all of tests for @opentelemetry/resources, @opentelemetry/resource-detector-*, and @opentelemetry/auto-instrumentations-node should catch this. My total guess is that there are no out-of-process tests for these, and that mocha has some uncaughtException or unhandledRejection process event handler that accidentally traps these.
  • I think the section in the migration guide (https://github.com/open-telemetry/opentelemetry-js/blob/main/doc/upgrade-to-2.x.md#-opentelemetryresources-changes-for-implementors-of-resource-detectors) should be updated to cope with this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • I'm really curious why tests didn't catch this: some or all of tests for @opentelemetry/resources, @opentelemetry/resource-detector-*, and @opentelemetry/auto-instrumentations-node should catch this.
  • @opentelemetry/resource-detector-*: At least for @opentelemetry/resource-detector-alibaba-cloud all the tests using detectResources would immediately (in the same tick) call resource?.waitForAsyncResources(), which results in the async try/catch in that method guarding against promise rejections in the async attrs.

I have a coming test case that adds this before the resource?.waitForAsyncResources():

import { setTimeout as setTimeoutP } from 'timers/promises';

// This pause simulates the delay between `detectResources` and
// `waitForAsyncAttributes` typically called later in an exporter.
await setTimeoutP(200); // Hope this is enough time to get error response.

This triggers the error.

  • @opentelemetry/auto-instrumentations-node: Its register.test.ts does do an out of process test. However, it sets OTEL_NODE_RESOURCE_DETECTORS: 'none', hence no testing of async resource detection. With the following diff, the test fails:
--- a/metapackages/auto-instrumentations-node/test/register.test.ts
+++ b/metapackages/auto-instrumentations-node/test/register.test.ts
@@ -33,7 +33,6 @@ function runWithRegister(path: string): PromiseWithChild<{
       timeout: 1500,
       killSignal: 'SIGKILL', // SIGTERM is not sufficient to terminate some hangs
       env: Object.assign({}, process.env, {
-        OTEL_NODE_RESOURCE_DETECTORS: 'none',
         OTEL_TRACES_EXPORTER: 'console',
         OTEL_LOG_LEVEL: 'debug',

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • I think there is effectively a regression in @opentelemetry/[email protected] here. It doesn't adequately guard against a rejection in async resource attribute values anymore. I'll raise an issue (and perhaps PR) for this.

I've opened open-telemetry/opentelemetry-js#5539 for this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be fixed in commit e3a689f

trentm added 3 commits March 17, 2025 18:00
…eject

Also tweak the auto-instrumentations-node/register.js test to actually use
resource detectors, to help test if there are issues with them.

Refs: open-telemetry/opentelemetry-js#5539
@pichlermarc pichlermarc merged commit 7fb4ba3 into open-telemetry:main Mar 18, 2025
23 checks passed
@dyladan dyladan mentioned this pull request Mar 18, 2025
@trentm trentm deleted the tm-sdk2-attempt branch March 18, 2025 19:21
trentm added a commit to trentm/opentelemetry-js-contrib that referenced this pull request Mar 18, 2025
…g now that target is es2022

As of open-telemetry#2738 the tsconfig target is es2022 now, so this special case is
no longer necessary.
deejay1 pushed a commit to deejay1/opentelemetry-js-contrib that referenced this pull request Apr 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

has:sponsor This package or feature has a sponsor that has volunteered to review PRs and respond to questions pkg:auto-configuration-propagators pkg:auto-instrumentations-node pkg:auto-instrumentations-web pkg:host-metrics pkg:id-generator-aws-xray pkg:instrumentation-amqplib pkg:instrumentation-aws-lambda pkg:instrumentation-aws-sdk pkg:instrumentation-bunyan pkg:instrumentation-cassandra-driver pkg:instrumentation-connect pkg:instrumentation-cucumber pkg:instrumentation-dataloader pkg:instrumentation-dns pkg:instrumentation-document-load pkg:instrumentation-express pkg:instrumentation-fastify pkg:instrumentation-fs pkg:instrumentation-generic-pool pkg:instrumentation-graphql pkg:instrumentation-hapi pkg:instrumentation-ioredis pkg:instrumentation-knex pkg:instrumentation-koa pkg:instrumentation-long-task pkg:instrumentation-lru-memoizer pkg:instrumentation-memcached pkg:instrumentation-mongodb pkg:instrumentation-mongoose pkg:instrumentation-mysql pkg:instrumentation-mysql2 pkg:instrumentation-nestjs-core pkg:instrumentation-net pkg:instrumentation-pg pkg:instrumentation-pino pkg:instrumentation-redis pkg:instrumentation-restify pkg:instrumentation-router pkg:instrumentation-runtime-node pkg:instrumentation-socket.io pkg:instrumentation-tedious pkg:instrumentation-undici pkg:instrumentation-user-interaction pkg:instrumentation-winston pkg:plugin-react-load pkg:propagation-utils pkg:propagator-aws-xray pkg:propagator-aws-xray-lambda pkg:propagator-instana pkg:propagator-ot-trace pkg:redis-common pkg:resource-detector-alibaba-cloud pkg:resource-detector-aws pkg:resource-detector-azure pkg:resource-detector-container pkg:resource-detector-gcp pkg:resource-detector-github pkg:resource-detector-instana pkg:sampler-aws-xray pkg:sql-common pkg:test-utils pkg-status:unmaintained:autoclose-scheduled pkg-status:unmaintained This package is unmaintained. Only bugfixes may be acceped until a new owner has been found.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

10 participants